package com.sicau.socialpracticesystem.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sicau.socialpracticesystem.entity.param.teaminstruction.TeamInstructionQueryParam;
import com.sicau.socialpracticesystem.entity.po.TeamInstruction;
import com.sicau.socialpracticesystem.entity.vo.PageDataVO;
import com.sicau.socialpracticesystem.entity.vo.teaminstruction.TeamInstructionVO;
import com.sicau.socialpracticesystem.mapper.TeamInstructionMapper;
import com.sicau.socialpracticesystem.mapper.VOMapper;
import com.sicau.socialpracticesystem.service.TeamInstructionService;
import com.sicau.socialpracticesystem.util.PageUtil;
import com.sicau.socialpracticesystem.util.QueryWrapperUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 支队介绍 服务实现类
 * </p>
 *
 * @author sxt && ttxxi
 * @since 2021-04-26
 */
@Service
public class TeamInstructionServiceImpl extends ServiceImpl<TeamInstructionMapper, TeamInstruction> implements TeamInstructionService {

    @Resource
    private VOMapper.TeamInstructionVOMapper teamInstructionVOMapper;

    /**
     * 排序属性
     */
    private static final String[] ORDER_COLUMN = {"id"};

    @Override
    public PageDataVO<TeamInstructionVO> queryTeamInstructionByConditions(TeamInstructionQueryParam teamInstructionQueryParam) {
        QueryWrapper<TeamInstructionVO> queryWrapper = QueryWrapperUtil.getQueryWrapper(TeamInstructionVO.class, TeamInstructionQueryParam.class, teamInstructionQueryParam);
        queryWrapper.orderByDesc(ORDER_COLUMN);
        Page<TeamInstructionVO> infoVOPage = new Page<>(teamInstructionQueryParam.getCurrentPage(), teamInstructionQueryParam.getPageSize());
        infoVOPage = teamInstructionVOMapper.selectPage(infoVOPage, queryWrapper);
        return PageUtil.convert(infoVOPage);
    }

    @Override
    public TeamInstructionVO queryTeamInstructionByTeamId(Integer teamId) {
        LambdaQueryWrapper<TeamInstructionVO> queryWrapper = new LambdaQueryWrapper<TeamInstructionVO>()
                .eq(TeamInstructionVO::getTeamId, teamId);
        return teamInstructionVOMapper.selectOne(queryWrapper);
    }
}
